package com.lz.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.lz.form.User;
import com.lz.service.LoginService;
import com.lz.util.PropertyReader;

public class LoginAction extends Action{

	public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
       throws IOException, ServletException{
		String FORWARD="ADMINMAIN";
          User user=new User();
          if(PropertyReader.getConfigProperty("adminloginid").equalsIgnoreCase(request.getParameter("loginid")) && PropertyReader.getConfigProperty("adminpwd").equalsIgnoreCase(request.getParameter("password")))
          {
              HttpSession session=request.getSession(true);
              session.setAttribute("user",user);
          }
          else{
              //Login id and pwd not matching.
              request.setAttribute("message","Incorrect Login Id or Password");
      	      return mapping.findForward("MESSAGE");
          }
          
         
                  
          return mapping.findForward(FORWARD); 
	}
	
	 public static  boolean isAdmin(HttpServletRequest request){
		 HttpSession session=request.getSession(true);
	         if(null!=session.getAttribute("user")){
	        
	             return true;
	    }
	         
	        
	         
	         return false;
	 }
	
}
